//
//  HYHomeViewController.m
//  SPlayer
//
//  Created by liguoqing on 2023/7/31.
//

#import "HYHomeViewController.h"
#import "HYHomeViewModel.h"
#import "HYHomeHeaderView.h"
#import <HYUIKit/HYMenuScrollView.h>
#import "HYHomeMainView.h"
#import "HYLocalPhotoVideoViewController.h"
#import "HYCreateVideoViewController.h"
#import "HYHomeVideoModel.h"
#import "HYHomeVideoListCell.h"
#import "HYVideoViewModel.h"
#import "HYAudioRoomViewController.h"
#import "HYVideoRoomViewController.h"
#import "JZTouchIDManager.h"
#import "LBXPermission.h"
#import "LBXPermissionSetting.h"
#import "StyleDIY.h"
#import "QQScanZXingViewController.h"
#import <HYUIKit/HYPopMenu.h>
#import "HYCreatFileAlertView.h"
#import "HYFileImportViewController.h"
#import "HYBDPanFIleListController.h"
#import "HYPCImportViewController.h"
#import "HYFolderMoveViewController.h"
#import "HYPhotoImportViewController.h"
#import "HYSuspendButton.h"
#import "HYPreviewHistoryManager.h"
#import "HYAlertActionView.h"
#import "HYMyCollectionViewController.h"
#import "HYFaceToFaceController.h"
#import <HYUIKit/HYWKWebViewController.h>

@interface HYHomeViewController ()

@property (nonatomic, strong) HYHomeViewModel *viewModel;

@property (nonatomic, strong) UIButton *navPlayBtn;

@property (nonatomic, strong) HYSuspendButton *createBtn;

@property (nonatomic, strong) HYHomeHeaderView *headerView;

@property (nonatomic, strong) HYHomeMainView *mainView;

@property (nonatomic, strong) HYHomeMainView *videoView;

@property (nonatomic, strong) HYHomeMainView *audioView;

@property (nonatomic, strong) UITextField *textField;

@end

@implementation HYHomeViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    if(!self.folderViewModel){
        self.navigationBarView.titleLabel.text = @"VPlayer";
        self.view.backgroundColor = AppBgThemeColor;
        self.navigationBarView.navagationBarStyle = Left_right_button_show;
        [self.navigationBarView.leftButton setImage:[UIImage imageNamed:@"icon_scan"] forState:UIControlStateNormal];
        HYLayoutType layoutType = [HYMineSetManager shareManager].layoutType;
        [self.navigationBarView.rightButton setImage:[UIImage imageNamed:layoutType?@"icon_list_mode":@"icon_grid_mode"] forState:UIControlStateNormal];
        [self.navigationBarView addSubview:self.navPlayBtn];
        [self.navPlayBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.navigationBarView.rightButton.mas_centerY);
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(30);
            make.right.equalTo(self.navigationBarView.rightButton.mas_left);
        }];
    }
    [self configUI];
    [self bindSignal];
    [self loadData];
}

- (void)configUI
{
    if(!self.folderViewModel){
        [self configHeaderView];
    }
    [self configCategoryView];
}

- (void)configHeaderView
{
    [self.view addSubview:self.headerView];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.navigationBarView.mas_bottom);
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(kHomeHeaderHeight+10);
    }];
}

- (void)configCategoryView
{
    CGFloat HeaderHeight = kHomeHeaderHeight+10;
    CGFloat hToolViewY = 0;
    CGFloat hToolHeight = [self preferredCategoryViewHeight];
    CGFloat tContainerHeight = 0;
    if(self.folderViewModel){
        hToolViewY = NAVIGATIONBAR_HEIGHT+2.5;
        tContainerHeight = kMainScreenHeight-hToolViewY-HOME_BAR_HEIGHT;
    }else{
        hToolViewY = NAVIGATIONBAR_HEIGHT+HeaderHeight;
        tContainerHeight = kMainScreenHeight-hToolViewY-hToolHeight-TABLE_BAR_HEIGHT;
    }
    CGFloat tContainerY = hToolViewY+hToolHeight;
    self.titles = @[NSLocalizedString(@"全部", nil),NSLocalizedString(@"视频", nil),NSLocalizedString(@"音频", nil)];
    self.myCategoryView.titles = self.titles;
    self.myCategoryView.frame = CGRectMake(0, hToolViewY, kScreenWidth, hToolHeight);
    self.listContainerView.frame = CGRectMake(0, tContainerY, kScreenWidth, tContainerHeight);
    [self.view addSubview:self.myCategoryView];
    [self.view addSubview:self.listContainerView];
    [self addCreateBtn];
    if(!self.folderViewModel){// 首页显示
        [self recordPreview];
    }
}

- (void)addCreateBtn
{
    [self.view addSubview:self.createBtn];
    [self.createBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-TABLE_BAR_HEIGHT-15);
        make.right.mas_equalTo(-kLeftMargin_15);
        make.width.height.mas_equalTo(60);
    }];
    [self.createBtn setImage:[UIImage imageNamed:@"icon_btn_add"]];
}

- (void)recordPreview
{
    @weakify(self);
    [HYPreviewHistoryManager showHistoryInView:self.view jump:^(BOOL isAudio, HYVideoViewModel *viewModel) {
        @strongify(self);
        if(isAudio){
            HYAudioRoomViewController *videoRoomVC = [[HYAudioRoomViewController alloc]initWithViewModel:viewModel];
            [self.navigationController pushViewController:videoRoomVC animated:YES];
        }else{
            HYVideoRoomViewController *videoRoomVC = [[HYVideoRoomViewController alloc]initWithViewModel:viewModel];
            [self.navigationController pushViewController:videoRoomVC animated:YES];
        }
    }];
}

- (void)bindSignal
{
    @weakify(self);
    [self.viewModel.showFileSubject subscribeNext:^(HYHomeFileItemViewModel *itemViewModel) {
        @strongify(self);
        switch (itemViewModel.fileType) {
            case HYHomeFileType_Document:// 文件导入
                {
                    [self showDocumentFolder:itemViewModel];
                }
                break;
            case HYHomeFileType_Photo: // 我的相册
                {
                    [self showPhotoVideo:itemViewModel];
                }
                break;
            case HYHomeFileType_Cloud: // 我的下载
                {
                    [self showMyCloudDisk:itemViewModel];
                }
                break;
            case HYHomeFileType_Collect: // 我的收藏
                {
                    [self showMyCollection:itemViewModel];
                }
                break;
            case HYHomeFileType_Folder: // 通用文件夹
                {
                    [self showCommonFolder:itemViewModel];
                }
                break;
            case HYHomeFileType_Video: // 视频
            case HYHomeFileType_Audio: // 音频
                {
                    HYVideoViewModel *viewModel = [self.viewModel fetchPlayVideoConfigWithItemViewModel:itemViewModel];
                    [self showVideo:itemViewModel videoViewModel:viewModel];
                }
                break;
                
            default:
                break;
        }
            
    }];
    // 文件设置
    [self.viewModel.setSubject subscribeNext:^(HYHomeFileItemViewModel *folderModel) {
        @strongify(self);
        [self setfolder:folderModel];
    }];
    
    [self.viewModel.refreshSubject subscribeNext:^(id x) {
        @strongify(self);
        if(self.refreshBlock){
            self.refreshBlock();
        }
    }];
    
    // 从其他页面新建视频传递过来的通知
    [kNotificationCenter addObserver:self selector:@selector(createVideoNotification:) name:kAddNewVideoNotification object:nil];
}

- (void)loadData
{
    [self.viewModel fetchData:HYHomeFileType_All];
}

#pragma mark - 列表布局样式
- (void)rightButtonClick
{
    [CommUtls touchImpactFeedbackGenerator];
    HYLayoutType layoutType = [HYMineSetManager shareManager].layoutType;
    [HYMineSetManager shareManager].layoutType = !layoutType;
    [self.navigationBarView.rightButton setImage:[UIImage imageNamed:layoutType?@"icon_grid_mode":@"icon_list_mode"] forState:UIControlStateNormal];
    // 刷新布局
    [self.mainView refreshLayoutType];
    [self.videoView refreshLayoutType];
    [self.audioView refreshLayoutType];
}

- (void)showPlayUrlAlert
{
    @weakify(self);
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"URL播放", nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        @strongify(self);
        self.textField = textField;
    }];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"播放", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        @strongify(self);
        if(self.textField.text.length){
            [self playVideoWithUrl:self.textField.text];
            self.textField = nil;
        }
    }];
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"取消", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        @strongify(self);
        self.textField = nil;
    }];
    [alert addAction:sureAction];
    [alert addAction:cancleAction];
    [self presentViewController:alert animated:YES completion:nil];
}

- (void)playVideoWithUrl:(NSString *)url
{
    BOOL isVideoUrl = [self.viewModel checkVideoPlayUrl:url];
    if(!isVideoUrl){
        [HYHub showMessage:NSLocalizedString(@"请输入有效的播放地址", nil) delay:2.0];
        return;
    }
    NSString *lastTitle = [url lastPathComponent];
    NSString *videoTitle = [CommUtls fetchVideoNameWithFullName:lastTitle];
    HYVideoModel *videoModel = [[HYVideoModel alloc]init];
    videoModel.videoUrl = url;
    videoModel.videoTitle = lastTitle;
    videoModel.videoImagePath = [videoTitle stringByAppendingFormat:@".png"];
    videoModel.videoImage = [CommUtls fetchVideoCoverImageWithUrl:url atTime:1.0];
    NSString *createDate = [CommUtls encodeTimeYearMonthDay:[NSDate date]];
    videoModel.createDate = createDate;
    videoModel.isSelect = YES;
    HYVideoPlayerConfig *config = [HYVideoPlayerConfig new];
    config.isBasePlayer = YES;
    config.currentVideoModel = videoModel;
    config.videoSoucres = @[videoModel];
    HYVideoViewModel *viewModel = [[HYVideoViewModel alloc]initWithFolderIdentification:@"URL-vplayer" isPrivate:NO videoConfig:config];
    HYVideoRoomViewController *videoVC = [[HYVideoRoomViewController alloc]initWithViewModel:viewModel];
    [self.navigationController pushViewController:videoVC animated:YES];
}


#pragma mark - 扫一扫
- (void)leftButtonClick
{
    if(!self.folderViewModel){
        @weakify(self);
        [LBXPermission authorizeWithType:LBXPermissionType_Camera completion:^(BOOL granted, BOOL firstTime) {
            @strongify(self);
            if (granted) {
                [self pushSanVc];
            }else if(!firstTime){
                [LBXPermissionSetting showAlertToDislayPrivacySettingWithTitle:NSLocalizedString(@"提示", nil)
                                                                           msg:NSLocalizedString(@"没有开启相机权限，是否前往设置", nil)
                                                                        cancel:NSLocalizedString(@"取消", nil)
                                                                       setting:NSLocalizedString(@"设置", nil)];
            }
        }];
    }else{
        [super leftButtonClick];
    }
}

#pragma mark - 跳转扫一扫
- (void)pushSanVc
{
    QQScanZXingViewController *vc = [QQScanZXingViewController new];
    vc.style = [StyleDIY qqStyle];
    vc.cameraInvokeMsg = NSLocalizedString(@"相机启动中", nil);
    vc.continuous = NO;
    vc.orientation = [StyleDIY videoOrientation];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 文件导入
- (void)showDocumentFolder:(HYHomeFileItemViewModel *)folderModel
{
    @weakify(self);
    [self pushFolderViewControllerIsLock:folderModel.isLock touchIdBlock:^(BOOL isSuccess, NSString *errorInfo) {
        @strongify(self);
        if(isSuccess){
            HYFileImportViewController *documentFolderVC = [[HYFileImportViewController alloc]initWithParentPath:@"" currentfolderPath:[HYFileManager documentDirectory] currentfolderName:NSLocalizedString(@"文件导入", nil)];
            [self.navigationController pushViewController:documentFolderVC animated:YES];
        }else{
            [HYHub showMessage:NSLocalizedString(@"识别失败，请重试！", nil)];
        }
    }];
}

#pragma mark - 相册视频
- (void)showPhotoVideo:(HYHomeFileItemViewModel *)folderViewModel
{
    @weakify(self);
    [self pushFolderViewControllerIsLock:folderViewModel.isLock touchIdBlock:^(BOOL isSuccess, NSString *errorInfo) {
        @strongify(self);
        if(isSuccess){
            HYLocalPhotoVideoViewController *myPhotoVC = [[HYLocalPhotoVideoViewController alloc]initWithFolderViewModel:folderViewModel];
            [self.navigationController pushViewController:myPhotoVC animated:YES];
        }else{
            [HYHub showMessage:NSLocalizedString(@"识别失败，请重试！", nil)];
        }
    }];
}

#pragma mark - 我的下载
- (void)showMyCloudDisk:(HYHomeFileItemViewModel *)folderViewModel
{
    @weakify(self);
    [self pushFolderViewControllerIsLock:folderViewModel.isLock touchIdBlock:^(BOOL isSuccess, NSString *errorInfo) {
        @strongify(self);
        if(isSuccess){
            //先判断是否有accessToken 没有的话去通过简化模式获取token保存token 同时获取用户VIP信息等
            //如果有accessToken的话 每次通过过去用户信息检查accessToken是否失效，失效后清除原来的token和用户信息 简化模式获取token保存token 同时获取用户VIP信息等
            @weakify(self);
            if ([BDPanOauthManager manager].accessToken.length != 0){
                [[BDPanOauthManager manager] getUserInfo:^(NSString * _Nonnull errorStr) {
                    @strongify(self)
                    if (errorStr.length) {
                        [[BDPanOauthManager manager] disableOauthInfo];
                        [self requestBDToken];
                        return;
                    }
                    HYBDPanFIleListController *fileListVC = [[HYBDPanFIleListController alloc]init];
                    fileListVC.isHome = YES;
                    [self.navigationController pushViewController:fileListVC animated:YES];
                }];
            }else {
                [self requestBDToken];
            }
        }else{
            [HYHub showMessage:NSLocalizedString(@"识别失败，请重试！", nil)];
        }
    }];
}

- (void)requestBDToken
{
    @weakify(self);
    NSString *url = [NSString stringWithFormat:@"http://openapi.baidu.com/oauth/2.0/authorize?response_type=token&client_id=%@&redirect_uri=%@&scope=%@&display=mobile",[BDPanOauthManager manager].BDPanOauthAppkey,[BDPanOauthManager manager].BDPanOauthrRedirectURI,[BDPanOauthManager manager].BDPanOauthScope];
    HYWKWebViewController *vc = [[HYWKWebViewController alloc]init];
    vc.hiddenNavigationBar = YES;
    vc.netUrl = url;
    vc.getBDaccessToken = ^(NSString * _Nullable token) {
        @strongify(self);
        [BDPanOauthManager manager].accessToken = token;
        HYBDPanFIleListController *fileListVC = [[HYBDPanFIleListController alloc]init];
        fileListVC.isHome = YES;
        [self.navigationController pushViewController:fileListVC animated:YES];
    };
    [self presentViewController:vc animated:YES completion:nil];
}

#pragma mark - 我的收藏
- (void)showMyCollection:(HYHomeFileItemViewModel *)folderViewModel
{
    @weakify(self);
    [self pushFolderViewControllerIsLock:folderViewModel.isLock touchIdBlock:^(BOOL isSuccess, NSString *errorInfo) {
        @strongify(self);
        if(isSuccess){
            HYMyCollectionViewController *collectionVC = [[HYMyCollectionViewController alloc]initWithFolderViewModel:folderViewModel];
            [self.navigationController pushViewController:collectionVC animated:YES];
        }else{
            [HYHub showMessage:NSLocalizedString(@"识别失败，请重试！", nil)];
        }
    }];
}

#pragma mark - 查看通用文件夹
- (void)showCommonFolder:(HYHomeFileItemViewModel *)folderViewModel
{
    @weakify(self);
    [self pushFolderViewControllerIsLock:folderViewModel.isLock touchIdBlock:^(BOOL isSuccess, NSString *errorInfo) {
        @strongify(self);
        if(isSuccess){
            HYHomeViewController *commonFolderVC = [[HYHomeViewController alloc]initWithFolderViewModel:folderViewModel];
            [commonFolderVC fileChangeRefreshBlock:^{
                @strongify(self);
                [self loadData];
            }];
            [self.navigationController pushViewController:commonFolderVC animated:YES];
        }else{
            [HYHub showMessage:NSLocalizedString(@"识别失败，请重试！", nil)];
        }
    }];
}

#pragma mark - 新建资源
- (void)createBtnAction
{
    HYCreatFileAlertView *alertView = [[HYCreatFileAlertView alloc]initWithItemTypes:@[@(HYCreatFileType_Folder),@(HYCreatFileType_Video),@(HYCreatFileType_Audio),@(HYCreatFileType_Photo),@(HYCreatFileType_Import),@(HYCreatFileType_FaceToFace)] clickBlock:^(HYCreatFileType type) {
        switch (type) {
            case HYCreatFileType_Folder:
                {
                    [self newCreateFolder:YES fileViewModel:nil];
                }
                break;
            case HYCreatFileType_Video:
                {
                    [self createAudioOrVideoByUrl:YES];
                }
                break;
            case HYCreatFileType_Audio:
                {
                    [self createAudioOrVideoByUrl:NO];
                }
                break;
            case HYCreatFileType_Import:
                {
                    [self pcImport:[self.viewModel fetchMyDocumentViewModel]];
                }
                break;
            case HYCreatFileType_Photo:
                {
                    [self photoImport];
                }
                break;
            case HYCreatFileType_FaceToFace:
                {
                    [self faceToFaceFileTransfer];
                }
                break;
            default:
                break;
        }
    }];
    [alertView show];
}

#pragma mark - 文件设置
- (void)setfolder:(HYHomeFileItemViewModel *)folderVM
{
    NSArray *itemsTypes;
    if(folderVM.fileType == HYHomeFileType_Document || folderVM.fileType == HYHomeFileType_Cloud || folderVM.fileType == HYHomeFileType_Photo || folderVM.fileType == HYHomeFileType_Collect){
        itemsTypes = @[folderVM.isLock?@(HYCreatFileType_unLock):@(HYCreatFileType_Lock)];
    }else{
        itemsTypes = @[@(HYCreatFileType_Rename),@(HYCreatFileType_Delete),@(HYCreatFileType_Move),folderVM.isLock?@(HYCreatFileType_unLock):@(HYCreatFileType_Lock)];
    }
    @weakify(self);
    HYCreatFileAlertView *alertView = [[HYCreatFileAlertView alloc]initWithItemTypes:itemsTypes clickBlock:^(HYCreatFileType type) {
        @strongify(self);
        switch (type) {
            case HYCreatFileType_Rename:// 文件重命名
                {
                    [self newCreateFolder:NO fileViewModel:folderVM];
                }
                break;
            case HYCreatFileType_Delete:// 移动删除
                {
                    [HYAlertActionView showViewControler:self title:NSLocalizedString(@"温馨提示", nil) message:NSLocalizedString(@"删除后无法恢复，请谨慎操作！", nil) actionTitle:@[NSLocalizedString(@"确定", nil),NSLocalizedString(@"取消", nil)] sureBlock:^{
                        @strongify(self);
                        [self.viewModel deleteFilWithFileViewModel:folderVM];
                    } cancelBlock:nil];
                }
                break;
            case HYCreatFileType_Move:// 移动文件
                {
                    NSArray *folderSource = [self.viewModel fetchCurrentListFolder:folderVM];
                    [self moveFolder:folderVM folderSource:folderSource];
                }
                break;
            case HYCreatFileType_Lock:// 设为私密
                {
                    folderVM.isLock = !folderVM.isLock;
                    if(![HYMineSetManager shareManager].isPrivacyTip){
                        [HYAlertActionView showViewControler:self title:NSLocalizedString(@"温馨提示", nil) message:NSLocalizedString(@"设置私密后，将不会在播放记录和收藏中显示！", nil) actionTitle:@[NSLocalizedString(@"继续且不再提示", nil),NSLocalizedString(@"继续", nil)] sureBlock:^{
                            @strongify(self);
                            [HYMineSetManager shareManager].isPrivacyTip = YES;
                            [self.viewModel lockOrUnLockFoldeWithFileViewModel:folderVM];
                        } cancelBlock:^{
                            @strongify(self);
                            [self.viewModel lockOrUnLockFoldeWithFileViewModel:folderVM];
                        }];
                    }else{
                        [self.viewModel lockOrUnLockFoldeWithFileViewModel:folderVM];
                    }
                }
                break;
            case HYCreatFileType_unLock:// 解除私密
                {
                    [JZTouchID openTouchId:^(BOOL isSuccess, NSString *errorInfo) {
                        @strongify(self);
                        folderVM.isLock = !folderVM.isLock;
                        [self.viewModel lockOrUnLockFoldeWithFileViewModel:folderVM];
                    }];
                }
                break;
            default:
                break;
        }
    }];
    [alertView show];
}

#pragma mark - 新建文件夹/文件重命名
- (void)newCreateFolder:(BOOL)isNewCreate fileViewModel:(HYHomeFileItemViewModel *)fileVM
{
    @weakify(self);
    NSString *title = isNewCreate?NSLocalizedString(@"新建文件夹", nil):NSLocalizedString(@"重命名", nil);
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        @strongify(self);
        if(!isNewCreate){
            textField.text = [CommUtls fetchVideoNameWithFullName:fileVM.fileName];
        }
        self.textField = textField;
    }];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"确定", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        @strongify(self);
        if(self.textField.text.length){
            if(isNewCreate){// 新建文件夹
                [self.viewModel addNewFolderWithFolderName:self.textField.text completeBlock:nil];
            }else{// 修改文件名称
                if(![fileVM.fileName isEqualToString:self.textField.text]){
                    if(fileVM.fileSuffixName){
                        fileVM.fileName = [self.textField.text stringByAppendingFormat:@".%@",fileVM.fileSuffixName];
                    }else{
                        fileVM.fileName = self.textField.text;
                    }
                    [self.viewModel modifyFileNameWithFileViewModel:fileVM];
                }
            }
        }
        self.textField = nil;
    }];
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"取消", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        @strongify(self);
        self.textField = nil;
    }];
    [alert addAction:sureAction];
    [alert addAction:cancleAction];
    [self presentViewController:alert animated:YES completion:nil];
}

#pragma mark - 新建视频
- (void)createAudioOrVideoByUrl:(BOOL)isVideo
{
    HYCreateVideoViewController *addVideoVC = [[HYCreateVideoViewController alloc]initWithFolderIdentification:self.viewModel.folderIdentification isVideo:isVideo];
    @weakify(self);
    [addVideoVC saveAudioOrVideoInfoSuccessBlock:^(id model){
        @strongify(self);
        HYHomeVideoModel *videoModel = (HYHomeVideoModel *)model;
        [self.viewModel addNewVideoWithVideoModel:videoModel];
    }];
    [self.navigationController pushViewController:addVideoVC animated:YES];
}

- (void)createVideoNotification:(NSNotification *)notify
{
    id object = notify.object;
    if([object isKindOfClass:[NSDictionary class]]){
        NSDictionary *videoInfo = (NSDictionary *)object;
        NSString *folderIdentification = videoInfo[@"folderIdentification"];
        if([folderIdentification isEqualToString:self.viewModel.folderIdentification]){
            HYHomeVideoModel *videoModel = (HYHomeVideoModel *)videoInfo[@"videoModel"];
            [self.viewModel addNewVideoWithVideoModel:videoModel];
        }
    }else if ([object isKindOfClass:[HYHomeVideoModel class]]){
        HYHomeVideoModel *videoModel = (HYHomeVideoModel *)object;
        [self.viewModel addNewVideoWithVideoModel:videoModel];
    }
}

#pragma mark - 移动文件
- (void)moveFolder:(HYHomeFileItemViewModel *)fileViewModel folderSource:(NSArray *)folderSource
{
    HYFolderMoveViewController *folderVC = [[HYFolderMoveViewController alloc]initWithFolderSource:folderSource];
    folderVC.fileViewModel = fileViewModel;
    folderVC.viewModel = self.viewModel;
    folderVC.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:folderVC animated:YES completion:nil];
}

#pragma mark - PC导入
- (void)pcImport:(HYHomeFileItemViewModel *)fileViewModel
{
    HYPCImportViewController *pcVC = [[HYPCImportViewController alloc]init];
    [self.navigationController pushViewController:pcVC animated:YES];
}

#pragma mark - 相册导入
- (void)photoImport
{
    HYPhotoImportViewController *photoVC = [[HYPhotoImportViewController alloc]initWithImportFileFolderIdentification:self.viewModel.folderIdentification isPrivate:self.viewModel.isPrivate];
    photoVC.maxSelectCount = 9;
    [self.navigationController pushViewController:photoVC animated:YES];
}
#pragma mark - 面对面传送
- (void)faceToFaceFileTransfer
{
    HYFaceToFaceController *vc = [[HYFaceToFaceController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 查看视频/音频
- (void)showVideo:(HYHomeFileItemViewModel *)fileViewModel videoViewModel:(HYVideoViewModel *)viewModel
{
    @weakify(self);
    [self pushFolderViewControllerIsLock:fileViewModel.isLock touchIdBlock:^(BOOL isSuccess, NSString *errorInfo) {
        @strongify(self);
        if(isSuccess){
            if(fileViewModel.fileType == HYHomeFileType_Audio){
                HYAudioRoomViewController *videoRoomVC = [[HYAudioRoomViewController alloc]initWithViewModel:viewModel];
                [self.navigationController pushViewController:videoRoomVC animated:YES];
            }else{
                HYVideoRoomViewController *videoRoomVC = [[HYVideoRoomViewController alloc]initWithViewModel:viewModel];
                [self.navigationController pushViewController:videoRoomVC animated:YES];
            }
        }else{
            [HYHub showMessage:NSLocalizedString(@"识别失败，请重试！", nil)];
        }
    }];
}

#pragma mark - 跳转文件判断是否上锁
- (void)pushFolderViewControllerIsLock:(BOOL)isLock touchIdBlock:(HYBSuccessBlock)touchIDBlock
{
    if(isLock){
        [[JZTouchIDManager shareManager]openTouchId:touchIDBlock];
    }else{
        touchIDBlock(YES,@"");
    }
}

#pragma mark - JXCategoryListContentViewDelegate
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index
{
    HYHomeMainView *mainView;
    if(index == 0){
        mainView = [[HYHomeMainView alloc]initWithViewModel:self.viewModel fileType:HYHomeFileType_All];
        self.mainView = mainView;
    }else if (index == 1){
        mainView = [[HYHomeMainView alloc]initWithViewModel:self.viewModel fileType:HYHomeFileType_Video];
        self.videoView = mainView;
    }else if (index == 2){
        mainView = [[HYHomeMainView alloc]initWithViewModel:self.viewModel fileType:HYHomeFileType_Audio];
        self.audioView = mainView;
    }
    return mainView;
}

#pragma mark - loadLazy
- (HYHomeViewModel *)viewModel
{
    if(!_viewModel){
        if(self.folderViewModel){
            _viewModel = [[HYHomeViewModel alloc]initWithFolderLocation:self.folderViewModel.folderLocation
                                                   folderIdentification:self.folderViewModel.folderIdentification];
            _viewModel.isPrivate = self.folderViewModel.isLock;
        }else{
            _viewModel = [[HYHomeViewModel alloc]initWithFolderLocation:@""
                                                   folderIdentification:@"homePage-vplayer"];
        }
    }
    return _viewModel;
}

- (UIView *)createBtn
{
    if(!_createBtn){
        @weakify(self);
        _createBtn = [[HYSuspendButton alloc]initWithClickBlock:^{
            @strongify(self);
            [self createBtnAction];
        } margin:kLeftMargin_15];
        _createBtn.layer.cornerRadius = 30;
        _createBtn.layer.masksToBounds = YES;
    }
    return _createBtn;
}

#pragma mark - loadLazy
- (HYHomeHeaderView *)headerView
{
    if(!_headerView){
        _headerView = [[HYHomeHeaderView alloc]initWithViewModel:self.viewModel];
    }
    return _headerView;
}

- (UIButton *)navPlayBtn
{
    if(!_navPlayBtn){
        _navPlayBtn = [[UIButton alloc]init];
        [_navPlayBtn setImage:[UIImage imageNamed:@"play_logo_mode"] forState:UIControlStateNormal];
        [_navPlayBtn addTarget:self action:@selector(showPlayUrlAlert) forControlEvents:UIControlEventTouchUpInside];
    }
    return _navPlayBtn;
}

@end
